package ManagedBeans;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
import SessionBeans.ProductosDAO;
import Utilidades.CSV;
import Utilidades.Utilidades;
import java.io.File;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.icefaces.ace.component.fileentry.FileEntry;
import org.icefaces.ace.component.fileentry.FileEntryEvent;
import org.icefaces.ace.component.fileentry.FileEntryResults;

/**
 *
 * @author Ivan
 */
@ManagedBean
@RequestScoped
public class mbFileEntryController {

    public mbFileEntryController() {
    }

    public String listener(FileEntryEvent event) {
        FileEntry fileEntry = (FileEntry) event.getSource();
        FileEntryResults results = fileEntry.getResults();
        for (FileEntryResults.FileInfo fileInfo : results.getFiles()) {
            if (fileInfo.isSaved()) {

                ProductosDAO misProductos = Utilidades.getProductosDAO();
                File ruta = fileInfo.getFile();

                CSV fichCsv = new CSV(ruta.toString(), ",", misProductos);
                if (fichCsv.error()) {
                    System.err.println("Error: " + fichCsv.getErrorMsg());
                }
            }
        }
        return "";
    }
}
